﻿{include file="public/header"/}
</head>
<body>
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">角色名：</label>
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input" type="text" placeholder="输入关键字"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchRole" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button data-type="authrole_add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="tableRole" lay-filter="tableRole"></table>
        </div>
    </div>
</div>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateUser">
<input type="checkbox" lay-filter="ckStateUser" data-id="{{d.id}}" value="{{d.status}}" lay-skin="switch" lay-text="正常|锁定" {{d.status == 1 ? 'checked':''}}/>
</script>
<script type="text/html" id="roleTbBar">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-type="authrole_edit" data-id="{{d.id}}">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" data-type="authrole_del" data-url="{:url('/authrole/del')}" data-id="{{d.id}}">删除</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'zTree'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var util = layui.util;

            // 渲染表格
            var insTb = table.render({
                elem: '#tableRole',
                url: "{:url('/authrole/index')}",
                page: true,
                cellMinWidth: 100,
                cols: [[
                    {field:'id',title:'ID',width:60},
                    {field: 'name',title: '角色名',width:180},
                    {field: 'online_update', title: '在线升级',align: 'center',templet: function (d) {
                        if (d.online_update ==1) {
                            return '是';
                        } else {
                            return '否';
                        }
                    },width:180},
                    {field: 'only_oneself', title: '文档权限',align: 'center',templet: function (d) {
                        if (d.only_oneself ==1) {
                           return '只能看自己发布';
                        } else {
                           return '查看全部';
                        }
                    },width:180},
                    {field: 'remark', title: '备注'},
                    {field: 'add_time', title: '创建时间', width: 200,align: 'center',},
                    {field: 'status', templet: '#tableStateUser', title: '状态',width: 100,align: 'center'},
                    {toolbar: '#roleTbBar', title: '操作',align: 'center', width: 200}
                ]]
            });

            // 搜索
            form.on('submit(formSubSearchRole)', function (data) {
                insTb.reload({where: data.field}, 'data');
            });

            $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
              var type = $(this).data('type');
              active[type] && active[type].call(this);
            });

            // 触发事件
            var active = {
                authrole_add: function(){
                    layer.open({
                        type: 2,
                        title: '添加权限',
                        fixed: true,
                        shadeClose: false,
                        shade: 0.3,
                        area: ['100%', '100%'],
                        content: "{:url('/authrole/add')}"
                    });
                },
                authrole_edit: function(){
                    var id = $(this).attr('data-id');
                    layer.open({
                        type: 2,
                        title: '修改权限',
                        fixed: true,
                        shadeClose: false,
                        shade: 0.3,
                        area: ['100%', '100%'],
                        content: "{:url('/authrole/edit')}?id="+id
                    });
                },
                authrole_del: function(){
                    delfun(this);
                }
            };

            //开启关闭
            form.on('switch(ckStateUser)', function(obj){
                var dataid = $(this).attr('data-id');
                var pcfurl = '{:url("/ajax/ajax_changeTableVal")}';
                if (obj.elem.checked){
                    $(this).val(1);
                }else{
                    $(this).val(0);
                }
                changeTableVal('auth_role','id',dataid,'status',this,pcfurl,'authrole/index');
            });
    });
</script>
</body>
</html>